﻿using ET.DBCommon.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ET.ScoreTeacherClient.Views
{
    /// <summary>
    /// UserEdit.xaml 的交互逻辑
    /// </summary>
    public partial class UserEdit : Window
    {
        public UserViewModel ViewModel { get; set; }
        public UserEdit(UserViewModel _viewModel)
        {
            InitializeComponent();
            this.ViewModel = _viewModel;
            this.DataContext = this;
        }

        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            if (ViewModel.Id == 0)
            {
                int newId = 0;
                if (UserInfoDAL.InsertUser(out newId, ViewModel.Model))
                {
                    ViewModel.Id = newId;
                    this.DialogResult = true;
                }
            }
            else
            {
                if (UserInfoDAL.UpdateUser(ViewModel.Model))
                {
                    this.DialogResult = true;
                }
            }
        }

        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
